/*
**    Name: ODBCLib.h
**
**    Date: Thu Jan 17 15:16:18 2002
**
**    Used for SWI level access only.
**
*/

#ifndef ODBCLIB_H
#define ODBCLIB_H

#define ODBCLIBMAXPARAMETERS 16
#define ODBCLIBMAXBOUNDPARAMETERS 256

/* Parameter types */

typedef enum  {
    ODBC_VALUE,
    ODBC_REFERENCE,
    ODBC_BOUNDREFERENCE
} ODBCLibParameterType;

/* Query status */

typedef enum  {
    ODBC_STATE_NOSERVER,
    ODBC_STATE_READY,
    ODBC_STATE_PENDING,
    ODBC_STATE_COMPLETE,
    ODBC_STATE_FINISHED
} ODBCLibState;

/* Windows that need opening or refreshing */

typedef struct _ODBCLibWindow {
    int w;
    int type;
} ODBCLibWindow;

/* Parameter structure */

typedef struct _ODBCLibParameter {
    ODBCLibParameterType type;
    int size;
    int value;
} ODBCLibParameter;

/* Bound parameter structure */

typedef struct _ODBCLibBoundParameter {
    int stmt;
    int data;
    int rmadata;
    int size;
} ODBCLibBoundParameter;

/* Query type structure */

typedef struct _ODBCLibQueryType {
    int type;
    int subtype;
    ODBCLibState state;
    int reply;
    int task;
    int version;
    ODBCLibParameter parameters[ODBCLIBMAXPARAMETERS];
    ODBCLibBoundParameter boundparameters[ODBCLIBMAXBOUNDPARAMETERS];
} ODBCLibQueryType;

extern int odbclibquit;

extern int odbclibversion;

#ifdef __cplusplus
extern "C" {
#endif

typedef int odbclib_loop(void );

/* Wait for free query slot */

int ODBCLibWait(ODBCLibState state);

/* Wimp poll handler */

int ODBCLibPoll(ODBCLibState state);

/* Set finished state */

int ODBCLibFinished(void);

/* Initialise */

int ODBCLibInitialise(void);

/* Add window */

int ODBCLibAddWindow(int w,int type);

/* Refresh */

int ODBCLibRefresh(void);

/* Handle application poll loop */

int ODBCLibLoop(odbclib_loop *);

#ifdef __cplusplus
}
#endif

/* Messages */

#define message_SQL_PENDING  0x56700
#define message_SQL_COMPLETE 0x56701

/* SWI numbers */

#define SQL_Base                0x56740
#define SQL_Connection          SQL_Base
#define SQL_DriverInfo          SQL_Base + 1
#define SQL_DriverAttributes    SQL_Base + 2
#define SQL_Descriptor          SQL_Base + 3
#define SQL_Preparation         SQL_Base + 4
#define SQL_Request             SQL_Base + 5
#define SQL_Result              SQL_Base + 6
#define SQL_ResultInfo          SQL_Base + 7
#define SQL_SystemTables        SQL_Base + 8
#define SQL_Terminate           SQL_Base + 9
#define SQL_QueryStatus         SQL_Base + 10
#define SQL_ConnectionP         SQL_Base + 11
#define SQL_DriverInfoP         SQL_Base + 12
#define SQL_DriverAttributesP   SQL_Base + 13
#define SQL_DescriptorP         SQL_Base + 14
#define SQL_PreparationP        SQL_Base + 15
#define SQL_RequestP            SQL_Base + 16
#define SQL_ResultP             SQL_Base + 17
#define SQL_ResultInfoP         SQL_Base + 18
#define SQL_SystemTablesP       SQL_Base + 19
#define SQL_TerminateP          SQL_Base + 20
#define SQL_DMTask              SQL_Base + 21


/* Reason codes for SQL_Connection */

#define SQL_AllocConnect     0
#define SQL_AllocEnv         1
#define SQL_AllocHandle      2
#define SQL_AllocStmt        4
#define SQL_Connect          5
#define SQL_DriverConnect    6
#define SQL_BrowseConnect    7
#define SQL_FreeConnect      8
#define SQL_FreeEnv          9
#define SQL_FreeHandle       10
#define SQL_FreeStmt         11
#define SQL_Disconnect       12

/* Reason codes for SQL_DriverInfo */

#define SQL_DataSources  0
#define SQL_Drivers      1
#define SQL_GetFunctions 2
#define SQL_GetInfo      3
#define SQL_GetTypeInfo  4

/* Reason codes for SQL_DriverAttributes */

#define SQL_GetConnectAttr   0
#define SQL_SetConnectAttr   1
#define SQL_GetEnvAttr       2
#define SQL_SetEnvAttr       3
#define SQL_GetStmtAttr      4
#define SQL_SetStmtAttr      5
#define SQL_GetConnectOption 6
#define SQL_SetConnectOption 7
#define SQL_GetStmtOption    8
#define SQL_SetStmtOption    9

/* Reason codes for SQL_Descriptor */

#define SQL_GetDescField   0
#define SQL_SetDescField   1
#define SQL_GetDescRec     2
#define SQL_SetDescRec     3

/* Reason codes for SQL_Preparation */

#define SQL_Prepare          0
#define SQL_BindParameter    1
#define SQL_ParamOptions     2
#define SQL_GetCursorName    3
#define SQL_SetCursorName    4
#define SQL_SetScrollOptions 5
#define SQL_BindParam        6

/* Reason codes for SQL_Request */

#define SQL_Execute       0
#define SQL_ExecDirect    1
#define SQL_NativeSql     2
#define SQL_DescribeParam 3
#define SQL_NumParams     4
#define SQL_ParamData     5
#define SQL_PutData       6

/* Reason codes for SQL_Result */

#define SQL_BindCol        0
#define SQL_BulkOperations 1
#define SQL_Fetch          2
#define SQL_FetchScroll    3
#define SQL_ExtendedFetch  4
#define SQL_GetData        5
#define SQL_SetPos         6

/* Reason codes for SQL_ResultInfo */

#define SQL_ColAttribute  0
#define SQL_ColAttributes 1
#define SQL_DescribeCol   2
#define SQL_NumResultCols 3
#define SQL_RowCount      4
#define SQL_MoreResults   5
#define SQL_GetDiagField  6
#define SQL_GetDiagRec    7
#define SQL_Error         8

/* Reason codes for SQL_SystemTables */

#define SQL_ColumnPrivileges 0
#define SQL_Columns          1
#define SQL_SpecialColumns   2
#define SQL_ForeignKeys      3
#define SQL_PrimaryKeys      4
#define SQL_ProcedureColumns 5
#define SQL_Procedures       6
#define SQL_Statistics       7
#define SQL_TablePrivileges  8
#define SQL_Tables           9

/* Reason codes for SQL_Terminate */

#define SQL_CloseCursor 0
#define SQL_Cancel      1
#define SQL_EndTran     2
#define SQL_Transact    3

/* Query status */

#define SQL_QueryStatusSet        0
#define SQL_QueryStatusGet        1
#define SQL_QueryStatusParameters 2
#define SQL_QueryStatusReplySet   3
#define SQL_QueryStatusReplyGet   4
#define SQL_QueryStatusType       5

/* DM Task */

#define SQL_DMTaskSet 0
#define SQL_DMTaskGet 1

#endif
